const { regeneratorRuntime, connect, P } = global

Page(global.connect(
  state => ({
    ...state.globalReducer,
    ...state.profileReducer
  }),
  dispatch => ({
    handleRoute: global.handleRoute,
    async handleGetSMSCode(e) {
      console.log('handleGetSMSCode')
      if (this.data.uiCodeCount === 60) {
        const actionRes = await dispatch(global.profileReducer.getAuditSendCode({
          phone: this.data.mobile
        }))
        if (actionRes.actionStatus !== 'SUCCESS') {
          this.selectComponent('#toast').handleShow({
            message: actionRes.apiMes
          })
        }
      }
    },
    async handleSubmit(e) {
      console.log('handleSubmit', e)
      const { mobile, code, pw1, pw2 } = e.detail.value
      const formData = {
        mobile, code, pw1, pw2
      }
      try {
        const actionRes = await dispatch(global.profileReducer.resetPassword(formData))
        console.log(actionRes)
        if (actionRes.actionStatus === 'SUCCESS') {
          this.selectComponent('#toast').handleShow({
            type: 'success',
            message: actionRes.apiMes
          })
          setTimeout(() => {
            wx.navigateBack()
          }, 1000);
        } else {
          this.selectComponent('#toast').handleShow({
            message: actionRes.apiMes || '重置密码失败，请稍后再试'
          })
        }
      } catch (error) {
        console.log(error)
        this.selectComponent('#toast').handleShow({
          message: error.apiMes || '重置密码失败，请稍后再试'
        })
      }
    }
  })
)(P({
  onLoad() {
    console.log(`${this.route} onLoad`)
  },
  handleLicon1Tap(e) {
    console.log('handleLicon1Tap', e)
    wx.navigateBack()
  },
  handleInput(e) {
    console.log(e)
    const { field } = e.currentTarget.dataset
    const { value } = e.detail
    const obj = {}
    obj[field] = value
    this.setData(obj)
  }
})))